<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap-v4.6.0.css" />
    <link rel="stylesheet" href="./css/login.css" />
</head>

<body>
    <div class="login-box">
        <div class="form-group">
            <label for="username">Account</label>
            <!-- 账号 -->
            <input type="text" class="form-control" id="username" autocomplete="off" />
            <small id="emailHelp" class="form-text text-muted">The available account is <strong>admin</strong></small>
        </div>
        <div class="form-group">
            <!-- 密码 -->
            <label for="password">Password</label>
            <input type="password" class="form-control" id="password" />
            <small id="emailHelp" class="form-text text-muted">The available password is <strong>123456</strong></small>
        </div>
        <button type="submit" class="btn btn-primary" id="btnLogin">Submit</button>
    </div>

    <script src="./lib/axios.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

    <script>
        document.querySelector('#btnLogin').onclick = function () {
            const username = document.querySelector('#username').value
            const password = document.querySelector('#password').value
            //点按钮才拿输入框中的内容  所以写在点击事件里面
            console.log(username);
            axios.post('http://ajax-api.itheima.net/api/login', {
                //post请求第二个参数依旧是对象 只不过不是params了 params只在get里
                // username: 'admin',
                // password: '123456'
                username,
                password, //当属性名和属性值一样时 可以省略属性值的写法
            }).then((res) => {
                console.log(res);
                alert(res.data.message)
            }).catch((error) => { //catch 捕获错误 找不到接口的时候走进来 比如说接口写错了
                console.log('error');
                console.log(error);
            })
        }
    </script>

</body>

</html>